const { http, setToken, getToken, removeToken } = require("@/utils");
const { makeAutoObservable } = require("mobx");

class LoginStore {
    token = getToken || ''
    constructor() {
        makeAutoObservable(this)
    }

    setToken = async ({ mobile, code }) => {
        const res = await http.post('http://geek.itheima.net/v1_0/authorizations', { mobile, code })
        this.token = res.data.token
        setToken(res.data.token)
    }

    signOut = () => {
        removeToken()
        this.token = ''
        window.location.href = '/login'
    }
}

export default LoginStore